const crypto = require('crypto')

/**
 * 生成指定长度的随机字符串
 * @param {number} length 生成的字符串长度
 */
function getRandomString(length) {
    const bits = (length + 3) * 6
    const buf = crypto.randomBytes(Math.ceil(bits / 8))
    const result = buf.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
    return result.slice(0, length)
}


module.exports = getRandomString